~(function(window) {
    var MVP = function() {};
    MVP.model = function() {
        var M = {};
        M.data = {};
        M.conf = {};
        return {
            getData: function(m) {
                return M.data[m];
            },
            setData: function(m, v) {
                M.data[m] = v;
                return v;
            },
            getConf: function(c) {
                return M.conf[c];
            },
            setConf: function(c, v) {
                M.conf[c] = v;
                return v;
            }
        }
    };
    MVP.view = function() {
        var REPLACEKEY = '_REPLACEKEY_';
        function getHTML(str, replacePos) {}
        function eachArray(arr, fn) {
            for(var i = 0, len = arr.length; i < len; i++) {
                fn(i, arr[i], len);
            }
        }
        function formateItem(str, rep) {
            return str.replace(new RegExp(REPLACEKEY, 'g'), rep);
        }
        return function(str) {
            var part = str
                          .replace(/^\s+|\s+$/g, '')
                          .replace(/^\s+(>)\s+/g, '$1')
                          .split('>'),
                html = REPLACEKEY,
                item,
                nodeTpl;
            eachArray(part, function(partIndex, partValue, partLen) {
                item = partValue.split('+');
                nodeTpl = REPLACEKEY;
                eachArray(item, function(itemIndex, itemValue, itemLen) {
                    nodeTpl = formateItem(nodeTpl, getHTML(itemValue, itemIndex === itemLen - 1 ? ( (partIndex === partLen - 1) ? '' : 'in' ) : 'add'));
                })
                html = formateItem(html, nodeTpl);
            });
            return html;
        }
    };
    MVP.presenter = function() {
        var V = MVP.view;
        var M = MVP.model;
        var C = {
            nav: function(M, V) {
                var data = M.getData('nav');
                data[0].choose = 'choose';
                data[data.length - 1].last = 'last';
                // ……
            }
        };
        return {
            init: function() {
                for(var i in C) {
                    C[i] && C[i](M, V, i);
                }
            }
        };
    };
    MVP.init = function() {
        this.presenter.init();
    };
    window.MVP = MVP;
})(window);

window.onload = function() {
    MVP.init();
}
